package day_7;

import java.util.Stack;

public class ques2 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
//         Scanner scanner=new Scanner(System.in);
//         String str=scanner.nextLine();
        if(n==0||n%2!=0){
            return false;
        }
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<A.length();i++){
            char ch=A.charAt(i);
            if(ch=='('){
                stack.push(ch);
            }else if(ch==')'&&!stack.isEmpty()){
                stack.pop();
            }else{
                return false;
            }
        }

        return stack.isEmpty();
    }

}
